<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "@/views/system/hooks";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: 0,
    configName: "",
    redirectUri: "",
    appid: "",
    appSecret: "",
    fileUploadAddress: "",
    authField: "",
    anthTableName: "",
    disate: 0,
    remark: "",
    scop: "",
    loginUrl: ""
  })
});
const { switchStyle } = usePublicHooks();
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
const sexOptions = [
  {
    value: "snsapi_base",
    label: "snsapi_base"
  },
  {
    value: "snsapi_userinfo",
    label: "snsapi_userinfo"
  }
];
defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="配置名称" prop="configName">
      <el-input
        v-model="newFormInline.configName"
        clearable
        placeholder="请输入配置名称"
      />
    </el-form-item>

    <el-form-item label="AppId" prop="appid">
      <el-input
        v-model="newFormInline.appid"
        clearable
        placeholder="请输入微信appid"
      />
    </el-form-item>
    <el-form-item label="AppSecret" prop="appSecret">
      <el-input
        v-model="newFormInline.appSecret"
        clearable
        placeholder="请输入微信secret"
      />
    </el-form-item>

    <el-form-item label="授权网址" prop="redirectUri">
      <el-input
        v-model="newFormInline.redirectUri"
        clearable
        placeholder="请输入授权网址"
      />
    </el-form-item>
    <el-form-item label="授权类型" prop="scop">
      <el-select
        v-model="newFormInline.scop"
        placeholder="请选择授权类型"
        class="w-full"
        clearable
      >
        <el-option
          v-for="(item, index) in sexOptions"
          :key="index"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>

    <el-form-item label="文件路径" prop="fileUploadAddress">
      <el-input
        v-model="newFormInline.fileUploadAddress"
        clearable
        placeholder="请输入文件上传或下载的路径"
      />
    </el-form-item>

    <el-form-item label="登录网址" prop="loginUrl">
      <el-input
        v-model="newFormInline.loginUrl"
        clearable
        placeholder="请输入超时后登录的网址"
      />
    </el-form-item>

    <el-form-item label="认证配置" prop="authField">
      <el-input
        v-model="newFormInline.authField"
        clearable
        placeholder="请输入认证字段，即账号和认证码的内容"
      />
    </el-form-item>
    <el-form-item label="认证表名" prop="authTableName">
      <el-input
        v-model="newFormInline.authTableName"
        clearable
        placeholder="请输入认证表名"
      />
    </el-form-item>

    <el-form-item label="配置状态">
      <el-switch
        v-model="newFormInline.disate"
        inline-prompt
        :active-value="1"
        :inactive-value="0"
        active-text="启用"
        inactive-text="停用"
        :style="switchStyle"
      />
    </el-form-item>

    <el-form-item label="备注">
      <el-input
        v-model="newFormInline.remark"
        placeholder="请输入备注信息"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template>
